<template>
	<view class="yt-tabbar">
		<!-- 与包裹页面所有内容的元素u-page同级，且在它的下方 -->
		<u-tabbar 
		height="130rpx" 
		v-model="current" 
		:list="list" 
		:mid-button="false" 
		icon-size="65rpx"
		active-color="#BB0000FF"
		:hide-tab-bar="true">
		</u-tabbar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				current: 0
			}
		},
		created() {
			// let heart_test = '';
			// clearInterval(heart_test)
			// heart_test = setInterval(this.getmsg,1000)
		},
		beforeMount() {
			if(uni.getStorageSync('role')){
				this.list.splice(0,this.list.length)
				this.list.splice(0,0,{
					iconPath: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-baf89db3-4d55-4b1f-a05e-c0a1170f8dce/8f9a6ec6-9db5-4bf3-a9c4-899b046c1128.png",
					selectedIconPath: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-baf89db3-4d55-4b1f-a05e-c0a1170f8dce/58e981d5-4f7c-424f-9178-68a944b38b6d.png",
					text: '消息',
					count: uni.getStorageSync('count'),
					isDot: false,
					customIcon: false,
					pagePath:"/pages/msg/msg"
				})
				this.list.splice(1,0,{
					iconPath: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-baf89db3-4d55-4b1f-a05e-c0a1170f8dce/0ddc6e8d-655b-4f4f-9f1e-be01659a7c77.png",
					selectedIconPath: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-baf89db3-4d55-4b1f-a05e-c0a1170f8dce/c9b77762-e360-4050-8723-c9869ca181e3.png",
					customIcon: false,
					text:'工作台',
					pagePath:"/pages/index/index"
				})		
				this.list.splice(2,0,{
					iconPath: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-baf89db3-4d55-4b1f-a05e-c0a1170f8dce/7f28b509-c5ec-49e8-a392-82233d448540.png",
					selectedIconPath: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-baf89db3-4d55-4b1f-a05e-c0a1170f8dce/0682eea3-9b8c-4e56-8735-445deb4ad545.png",
					text: '我的',
					customIcon: false,
					pagePath:"/pages/myself/myself"
				})
				if(uni.getStorageSync('role').permission != "examine"){
					if(uni.getStorageSync('role').permission != "admin"){
						this.list.splice(0,1)
					}
				}else{
					this.list.splice(1,1)
				}
			}else{
				uniCloud.callFunction({
					name: 'uni-id-cf_mobile',
					data: {
						action:"getUserRole",
						params:{
							userRole:uni.getStorageSync('userRole')[0]
						}
					}
				}).then(({result}) => {
					uni.setStorageSync('role',result.data[0])
					this.list.splice(0,this.list.length)
					this.list.splice(0,0,{
						iconPath: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-baf89db3-4d55-4b1f-a05e-c0a1170f8dce/8f9a6ec6-9db5-4bf3-a9c4-899b046c1128.png",
						selectedIconPath: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-baf89db3-4d55-4b1f-a05e-c0a1170f8dce/58e981d5-4f7c-424f-9178-68a944b38b6d.png",
						text: '消息',
						count: uni.getStorageSync('count'),
						isDot: false,
						customIcon: false,
						pagePath:"/pages/msg/msg"
					})
					this.list.splice(1,0,{
						iconPath: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-baf89db3-4d55-4b1f-a05e-c0a1170f8dce/0ddc6e8d-655b-4f4f-9f1e-be01659a7c77.png",
						selectedIconPath: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-baf89db3-4d55-4b1f-a05e-c0a1170f8dce/c9b77762-e360-4050-8723-c9869ca181e3.png",
						customIcon: false,
						text:'工作台',
						pagePath:"/pages/index/index"
					})		
					this.list.splice(2,0,{
						iconPath: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-baf89db3-4d55-4b1f-a05e-c0a1170f8dce/7f28b509-c5ec-49e8-a392-82233d448540.png",
						selectedIconPath: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-baf89db3-4d55-4b1f-a05e-c0a1170f8dce/0682eea3-9b8c-4e56-8735-445deb4ad545.png",
						text: '我的',
						customIcon: false,
						pagePath:"/pages/myself/myself"
					})
					if(uni.getStorageSync('role').permission != "examine"){
						if(uni.getStorageSync('role').permission != "admin"){
							this.list.splice(0,1)
						}
					}else{
						this.list.splice(1,1)
					}
					console.log(result)
				}).catch(err => {
					console.log(err)
				})
			}
		},
		methods:{
			getmsg(){
				let db = uniCloud.database()
				db.collection('yt-spOuthouse').where({
					isfinish:false
				}).get().then(res=>{
					let {affectedDocs,code} = res.result
					this.list[0].count = affectedDocs
					uni.setStorageSync('count',affectedDocs)
				})
			}
		}
	}
</script>

<style lang="scss">
	.yt-tabbar{
		width: 100%;
	}
</style>
